package com.aaa.utils;

import com.aaa.pojo.LayUiTree;
import com.aaa.pojo.Menu;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TreeUtils {

    public TreeUtils() {
    }

    public static List<LayUiTree> fromMenuListToTreeList(List<Menu> menuList) {
        List<LayUiTree> treeList = new ArrayList();
        Iterator var2 = menuList.iterator();

        while(var2.hasNext()) {
            Menu menu = (Menu)var2.next();
            if (menu.getParentId() == 0) {
                LayUiTree tree = fromMenuToTree(menu);
                LayUiTree treeChildren = setTreeChildren(tree, menuList);
                treeList.add(treeChildren);
            }
        }

        return treeList;
    }

    public static LayUiTree setTreeChildren(LayUiTree tree, List<Menu> menuList) {
        List<LayUiTree> children = new ArrayList();
        Iterator var3 = menuList.iterator();

        while(var3.hasNext()) {
            Menu menu = (Menu)var3.next();
            if (menu.getParentId() == tree.getId()) {
                LayUiTree layUiTree = fromMenuToTree(menu);
                children.add(setTreeChildren(layUiTree, menuList));
            }
        }

        tree.setChildren(children);
        return tree;
    }

    public static LayUiTree fromMenuToTree(Menu menu) {
        LayUiTree layUiTree = new LayUiTree();
        layUiTree.setId(menu.getMenuId());
        layUiTree.setIcon(menu.getIcon());
        layUiTree.setTitle(menu.getMenuName());
        layUiTree.setUrl(menu.getUrl());
        return layUiTree;
    }
}
